package LCommon;

public class TreeMethod {
	public TreeNode generateTree(String[] arr, int start) {
		if (arr[start] == "null") {
			return null;
		}
		TreeNode root = new TreeNode(Integer.valueOf(arr[start]));
		int lnode = start * 2 + 1;
		int rnode = start * 2 + 2;
		if (lnode > arr.length - 1) {
			root.left = null;
		} else {
			root.left = generateTree(arr, lnode);
		}
		if (rnode > arr.length - 1) {
			root.right = null;
		} else {
			root.right = generateTree(arr, rnode);
		}
		return root;

	}

	public void printTree(TreeNode root) {
		if (root == null) {
			System.out.println("null");
			return;
		}
		System.out.println(root.val);
		printTree(root.left);
		printTree(root.right);
	}

}
